// index.vue

<template>
	<view class="content">
		<image class="logo" src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/uploads/2023-07-29/miniMan.png" @click="selectFile"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
	</view>
</template>

<script>
	import { ossImage } from '../../utils/ossUpload.js';
	export default {
		data() {
			return {
				title: '选择上传的图片'
			}
		},

		methods: {
			selectFile() {
				let that = this
				uni.chooseImage({
					count: 9, // 默认最多一次选择9张图
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						console.log(res)
						let tempFilePaths = res.tempFilePaths; //本地临时路径
						for(var i = 0; i < tempFilePaths.length; i++){
							if (res.tempFiles[i].size > OSS.uploadFileSize) { //OSS.uploadFileSize在aliyun.js里面设置，
								uni.showToast({
									title: '文件【'+ (i+1) +'】超过系统上传限制大小：' + OSS.uploadFileSize,
									icon: 'none',
									duration: 3000
								});
								return;
							}else{
								// 调用上传函数
								ossImage('picture', tempFilePaths[i]).then(res=> {
									console.log("这是上传路径", res)
								})
							}							
						}
					}
				})
			},
			
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>

